package com.edu.service.impl;

import java.util.ArrayList;

import com.edu.dao.impl.GoodDaoImpl;
import com.edu.dao.impl.UserDaoImpl;
import com.edu.entity.Conditions;
import com.edu.entity.Goods;
import com.edu.entity.GoodsToWeb;
import com.edu.entity.Tool;
import com.edu.entity.User;
import com.edu.entity.reGoodsAndUser;

public class GoodServerImpl implements com.edu.service.GoodServer {

	@Override
	public ArrayList<GoodsToWeb> indexFindGoods(Goods g, Conditions con) {
		// TODO Auto-generated method stub
		Tool t1 = new Tool();
		GoodDaoImpl gdi = new GoodDaoImpl();
		ArrayList<Goods> l1 = gdi.sqlFindGoods(g, con);
		ArrayList<GoodsToWeb> l2 = new ArrayList();
		for(int i = 0;i<l1.size();i++) {
			GoodsToWeb gtw = new GoodsToWeb();
			Goods good = l1.get(i);
			gtw.setGoodname(good.getGoodname());
			gtw.setGooddec(good.getGooddec());
			gtw.setGoodFreightType(t1.freightIntToString(good.getGoodFreightType()));
			gtw.setGoodid(good.getGoodid());
			gtw.setGoodimg(good.getGoodimg());
			gtw.setGoodnum(good.getGoodnum());
			gtw.setGoodOnSellStat(good.getGoodOnSellStat());
			gtw.setGoodprice(good.getGoodprice());
			gtw.setOriprive(good.getOriprive());
			gtw.setGoodtype(t1.typeIntToString(good.getGoodtype()));
			gtw.setSellerId(good.getSellerId());
			gtw.setSeller(findSeller(good.getSellerId()));
			gtw.setGoodstat(t1.statIntToString(good.getGoodstat()));
			gtw.setGoodTradetType(t1.tradetIntToString(good.getGoodTradetType()));
			gtw.setBrand(good.getBrand());
			l2.add(gtw);
		}
		return l2;
	}
	public User findSeller(int i) {
		GoodDaoImpl gdi = new GoodDaoImpl();
		UserDaoImpl udi = new UserDaoImpl();
		User u = gdi.sqlFindSeller(i);
		u.setUserTags(udi.sqlFindUserTags(u));
		u.setOnSellGoodsNum(udi.sqlFindGoodsNum(i));
		return u;
	}
	@Override
	public int updateGoodsNum(Goods good, int i) {
		// TODO Auto-generated method stub
		GoodDaoImpl gdi = new GoodDaoImpl();
		return gdi.sqlUpdateGoodsNum(good, i);
	}

}
